/** @file unittest4.c
*   @brief isGameOver() tests
*/


#include "dominion.h"
#include "dominion_helpers.h"
#include <assert.h>
#include <stdio.h>
#include <limits.h>

int main(int argc, char **argv )
{

    printf("Running tests for isGameOver().\n");




    // game ends when no provinces left, or 3 piles empty (4 piles empty for 4 players)

    int nPlayers = 2;
    int k[]      = {adventurer,
                    council_room,
                    feast,
                    gardens,
                    mine,
                    remodel,
                    smithy,
                    village,
                    baron,
                    great_hall
                   };
    int seed = 2;
    struct gameState g1;

    initializeGame(nPlayers, k, seed, &g1);

    // new game
    assert (isGameOver(&g1) == 0);

    // out of province cards
    g1.supplyCount[province] = 0;
    assert (isGameOver(&g1)  == 1);

    // 3 piles empty
    g1.supplyCount[province]     = 1;
    g1.supplyCount[council_room] = 0;
    g1.supplyCount[feast]        = 0;
    g1.supplyCount[gardens]      = 0;
    assert(isGameOver(&g1) == 1);

    // 2 piles empty
    g1.supplyCount[province]     = 1;
    g1.supplyCount[council_room] = 1;
    g1.supplyCount[feast]        = 0;
    g1.supplyCount[gardens]      = 0;
    assert(isGameOver(&g1) == 0);

    // 4 piles empty
    g1.supplyCount[province]     = 1;
    g1.supplyCount[council_room] = 0;
    g1.supplyCount[feast]        = 0;
    g1.supplyCount[gardens]      = 0;
    g1.supplyCount[mine]         = 0;
    assert(isGameOver(&g1) == 1);

    // 3 piles empty and no province cards
    g1.supplyCount[province]     = 0;
    g1.supplyCount[council_room] = 0;
    g1.supplyCount[feast]        = 0;
    g1.supplyCount[gardens]      = 0;
    assert(isGameOver(&g1) == 1);


    // Repeat test with 4 players
    // Needs 4 piles empty with 4 players
    //

    nPlayers = 4;


    initializeGame(nPlayers, k, seed, &g1);

    // new game
    assert (isGameOver(&g1) == 0);

    // out of province cards
    g1.supplyCount[province] = 0;
    assert (isGameOver(&g1)  == 1);

    // 3 piles empty
    g1.supplyCount[province]     = 1;
    g1.supplyCount[council_room] = 0;
    g1.supplyCount[feast]        = 0;
    g1.supplyCount[gardens]      = 0;
    assert(isGameOver(&g1) == 0);

    // 2 piles empty
    g1.supplyCount[province]     = 1;
    g1.supplyCount[council_room] = 1;
    g1.supplyCount[feast]        = 0;
    g1.supplyCount[gardens]      = 0;
    assert(isGameOver(&g1) == 0);

    // 4 piles empty
    g1.supplyCount[province]     = 1;
    g1.supplyCount[council_room] = 0;
    g1.supplyCount[feast]        = 0;
    g1.supplyCount[gardens]      = 0;
    g1.supplyCount[mine]         = 0;
    assert(isGameOver(&g1) == 1);

    // 3 piles empty and no province cards
    g1.supplyCount[province]     = 0;
    g1.supplyCount[council_room] = 0;
    g1.supplyCount[feast]        = 0;
    g1.supplyCount[gardens]      = 0;
    assert(isGameOver(&g1) == 0);



    printf("Tests for isGameOver() passed.\n");


}
